<?php
session_start();

	if (( !isset($_SESSION['username']) ) AND ( $_GET['page'] == "home.php" ))
	{
		header ("Location: /index.php");
		exit;
	}
	
	if ($_SESSION['destuser'])
	{
		session_unregister('destuser');
	}
	
	$site_root = "";
	require_once ($site_root . "common/PinSQL.obj");
	$pinSQL = new PinSQL();
	
	$username = $_SESSION['username'];

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
	<title>The Pin Project | Home</title>
	<link rel="icon" type="image/ico" href="favicon.ico" />
	<link rel="stylesheet" type="text/css" href="topLevel.css" />
	<script type="text/javascript" src="javascript/pageutils.js"></script>
</head>

<body>
<div class="wrapper">

	<div class="top" style="display: block;" id="logo">
		<a href="javascript: toggleLogo()">
		
		
		<img src="img/logo-<?php
			$hour = date('G', time());
			if (( $hour >= 6 - 2 ) AND ( $hour < 18 - 2 ))
			{
				echo "day";
			} else {
				echo "night";
			}
		?>.png" border=0/>
		</a>
	</div>
	


	<div class="main" id="main" style="top: 270px;">
	
<?php
	
	if ( isset($_SESSION['username']) )
	{
		?>
	
		<div class="redmenu">
		
			<div class="redmenu_title">Logged In</div>
			
			<div class="horizontal_separation"></div>
			
			<div class="menu_text">

<?php
	$id = $_SESSION['id'];
	$pinSQL->Query("SELECT * FROM memberdata WHERE id='$id'");
	$row = $pinSQL->FetchNextRow();
	$picurl = $row['picurl'];
	
	$tWidth = 80;
	
	if ($picurl)
	{
		$imageSize = getimagesize("members/userData/$username/$picurl");
		
		if ($imageSize[0] <= $tWidth)
		{
			$newWidth = $imageSize[0];
			$newHeight = $imageSize[1];
		} else {
			$heightFactor = $imageSize[1] / $imageSize[0];
			$newWidth = $tWidth;
			$newHeight = $newWidth * $heightFactor;
		}
		
?>
		<img src="/members/userData/<?php echo $username . "/" . $picurl; ?>" width="<?php echo $newWidth; ?>" height="<?php echo $newHeight; ?>" />	
<?php

	}
	else
	{
		
?>
		<img src="/img/icons/nopic.png" width="<?php echo $tWidth; ?>" height="<?php echo $tWidth; ?>" />
		<br /><img src="/img/arrow_green.gif" /><a href="/members/frame.php?page=editProfile">Add a user picture</a>!
		<p />
<?php
	}
?>
			
				<b>Welcome, <?php echo $_SESSION['firstname']; ?></b>
				<div class="horizontal_separation"></div>
				<a href="/members/frame.php?page=profile&user=<?php echo $_SESSION['username']; ?>">My Profile</a>
				<br><a href="/members/frame.php?page=inbox">My Inbox</a>
				<br><a href="/members/frame.php?page=viewusers">View Users</a>
				<br><a href="/members/logout.php">Log out</a>
			</div>
			
			<div class="horizontal_separation"></div>
		</div>
	
		<div class="horizontal_separation"></div>
		
		<?php
	}
?>

		<div class="yellowmenu">
			<div class="yellowmenu_title">Menu</div>
		
			<div class="horizontal_separation"></div>
			
			<div class="menu_text">
				<a href="frame.php?page=home.php">Home</a>
				<br><a href="frame.php?page=aboutus.php">About Us</a>
				<br><a href="frame.php?page=contactus.php">Contact Us</a>
				<p />
				<img src="/img/icons/song_sm.png" /> <a href="/common/gallery/portal_music.php">Music</a>
				<br /><img src="/img/icons/picture_sm.png" /> <a href="/common/gallery/portal_pictures.php">Pictures</a>
			</div>
		</div>

		<div class="content">
			<?php
				$file = $_GET['page'];
				include $file;
			?>
		</div>

	</div>



</div>
</body><html><body></body></html>